package com.carhome.adapter;

import java.util.ArrayList;
import java.util.List;

import com.carhome.R;
import com.carhome.bean.CarSearchCondition;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CarFragmentSearchAdapter extends BaseAdapter {
	private Context context;
	private List<CarSearchCondition> list;

	public CarFragmentSearchAdapter(Context context) {
		this.context = context;
		list = new ArrayList<CarSearchCondition>();
	}

	public void addData(CarSearchCondition carSearchCondition) {
		list.add(carSearchCondition);
	}

	public int getCount() {
		return list.size();
	}

	public CarSearchCondition getItem(int position) {
		return list.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			convertView  = LayoutInflater.from(context).inflate(R.layout.car_fragment_search_listview_item, null);
			holder = new ViewHolder();
			holder.condition = (TextView) convertView.findViewById(R.id.car_fragment_search_condition);
			holder.conditionName = (TextView) convertView.findViewById(R.id.car_fragment_search_conditionName);
			holder.img = (ImageView) convertView.findViewById(R.id.car_fragment_search_conditionImg);
			convertView.setTag(holder);
		}
		holder = (ViewHolder) convertView.getTag();
		holder.condition.setText(getItem(position).condition);
		holder.conditionName.setText(getItem(position).conditionName);
		
		return convertView;
	}

	private class ViewHolder {
		TextView conditionName;
		TextView condition;
		ImageView img;
	}
}
